package ca.cbc.gisdigester.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import ca.cbc.gisdigester.Main;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * @author: arash
 * Date: 11-08-05
 * Time: 11:02 AM
 * CBC.ca All rights reserved.
 */
public enum XmlHelper {
	instance;
    private Logger logger = LoggerFactory.getLogger(XmlHelper.class);

    @SuppressWarnings("unchecked")
	public <T> T digestXmlFile(String instanceType, InputStream is) throws JAXBException {
        JAXBContext jc = JAXBContext.newInstance(instanceType);
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        logger.debug("Unmarshalled for " + instanceType + " type.");
        return (T) unmarshaller.unmarshal(is);
    }
    
    public Document readXML(InputStream stream) throws Exception {
    	DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    	DocumentBuilder db = dbf.newDocumentBuilder();
    	Document doc = db.parse(stream);    	
    	return doc;
    }
    
 
    
        
}
